﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Diagnostics;
using System.Collections;
using PSE.Deployment.SetupBase.Configuration;
using System.Reflection;
using System.Configuration;

namespace PSE.Deployment.SetupBase
{
    public class SetupApplication : ApplicationBase
    {
        protected override void OnApplicationStartup(object sender, StartupEventArgs e)
        {
            if (!IsCurrentProcessRunning())
            {
                base.OnApplicationStartup(sender, e);

                try
                {
                    SetupMainFactory.GetInstance().Execute();
                }
                catch (TypeInitializationException ex)
                {
                    if (ex.InnerException != null)
                        throw ex.InnerException;
                    else
                        throw;
                }
                catch
                {
                    throw;
                }
            }

            CloseApplication(SetupMainFactory.GetInstance().ExitCode);
        }

        protected override void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            base.OnDispatcherUnhandledException(sender, e);

            try
            {
                SetupMainFactory.GetInstance().Cancel();
            }
            catch
            {
                
            }
        }
    }
}
